package com.mfin.bs.mappers.impl;

import com.mfin.bom.interfaces.IPartner;
import com.mfin.vo.CustomerVO;
import com.mfin.vo.PartnerVO;
import com.mfin.vo.interfaces.IMappable;

public class PartnerMapper extends BaseMapper {

	@Override
	protected boolean doMap(IMappable fromArg, IMappable toArg) {
		boolean canPerformMap = false;

		if (fromArg instanceof IPartner && toArg instanceof PartnerVO) {
			canPerformMap = true;
			performMap((IPartner) fromArg, (PartnerVO) toArg);
		} else if (fromArg instanceof PartnerVO && toArg instanceof IPartner) {
			performMap((PartnerVO) fromArg, (IPartner) toArg);
			canPerformMap = true;
		}
		return canPerformMap;
	}

	private void performMap(PartnerVO fromArg, IPartner toArg) {
		if (fromArg.getPartnerId() != null) {
			toArg.setPartnerId(fromArg.getPartnerId());
		}
	}

	private void performMap(IPartner fromArg, PartnerVO toArg) {
		if (fromArg.getPartnerId() != null) {
			toArg.setPartnerId(fromArg.getPartnerId());
		}

		if (fromArg.getCustomer() != null) {
			map(fromArg.getCustomer(), (CustomerVO) toArg, false, false);
		}
	}
}
